package org.skill.panel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.math.BigDecimal;
import java.util.Map;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import org.come.bean.ConfigureBean;
import org.come.entity.RoleSummoning;
import org.come.model.Configure;
import org.come.until.UserMessUntil;
import org.come.until.Util;

import com.tool.btn.FormsOnOffBtn;
import com.tool.btn.PetLxBtn;
import com.tool.role.RoleData;
import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;

import io.netty.util.internal.StringUtil;

 

/**
 * 提升灵犀点主要面板
 * 
 * @author
 * 
 */
public class LXiulianMainPanel extends JPanel {

	private static final long serialVersionUID = 8760326700583559912L;

	private JLabel currentPoin // 当前灵犀等级
            , zhaohuanshou // 召唤兽名称
            , trainingProgress // 当前修炼进度
            , needExperience // 所需经验
            , currentExperience // 当前经验
            , needMoney // 所需金钱
            , needQinmi // 所需亲密
            , currentQinmi // 当前亲密
            ;

    private PetLxBtn promoteBtn // 提升修炼点按钮
            , exchangeBtn // 一键兑换按钮
            ;
    
    private int numExp;

    ConfigureBean allConfigure = UserMessUntil.getConfigureBean();
    Map<BigDecimal, Configure> item = allConfigure.getAllConfigure();
    Configure configure7 = item.get(new BigDecimal(7));
    int dhbsm = Integer.parseInt(configure7.getZqsld());
    int jysm = Integer.parseInt(configure7.getZqjnsx());
    int qmsm = Integer.parseInt(configure7.getJumpurl());


    private BigDecimal needMoneyNum = new BigDecimal(dhbsm);//扣出大话币
    private BigDecimal needExperienceNum = new BigDecimal(jysm);//扣除经验
    private BigDecimal needQinmiNum = new BigDecimal(qmsm);//扣除亲密
    public LXiulianMainPanel() {
    	
    	
        this.setPreferredSize(new Dimension(401,384));
        this.setOpaque(false);
        this.setLayout(null);

        // 关闭按钮事件
        //FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/old/2/1.png", 1, 83);
        //offBtn.setBounds(396 - 37, 10, 25, 25);
        //this.add(offBtn);

        // 组件初始化
        currentPoin = new JLabel("30");
        zhaohuanshou = new JLabel("召唤兽");
        trainingProgress = new JLabel("瓶颈");
        needExperience = new JLabel(needExperienceNum + "");
        currentExperience = new JLabel("1321321321");
        needMoney = new JLabel(needMoneyNum + "");
        needQinmi = new JLabel(needQinmiNum + "");
        currentQinmi = new JLabel("8888");

        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
        // 组件设置大小和方位
        	promoteBtn = new PetLxBtn("skin/8100226/newbutton/B22.png", 1, "提升修炼", 8,"");
            exchangeBtn = new PetLxBtn("skin/8100226/newbutton/B22.png", 1, "一键修炼", 9,"");
        	zhaohuanshou.setBounds(117, 40, 120, 18);
        	exchangeBtn.setBounds(75, 337, 99, 24);
            promoteBtn.setBounds(235, 337, 99, 24);
        }else {
            promoteBtn = new PetLxBtn("inkImg/hongmu/1_png.button.btn_xy.png", 1, "提升修炼", 8, Color.YELLOW);
            exchangeBtn = new PetLxBtn("inkImg/hongmu/1_png.button.btn_xy.png", 1, "一键修炼", 9, Color.YELLOW);
            zhaohuanshou.setBounds(70, 40, 220, 18);
            exchangeBtn.setBounds(75, 337, 80, 26);
            promoteBtn.setBounds(235, 337, 80, 26);
        }
        currentPoin.setBounds(310, 40, 45, 16);
        trainingProgress.setBounds(200, 73, 150, 17);
        needExperience.setBounds(200, 152, 150, 16);
        currentExperience.setBounds(200, 183, 150, 16);
        needMoney.setBounds(200, 214, 150, 16);
        needQinmi.setBounds(200, 276, 150, 16);
        currentQinmi.setBounds(200, 307, 150, 16);

        // 组件内容居中
        currentPoin.setHorizontalAlignment(SwingConstants.CENTER);
        trainingProgress.setHorizontalAlignment(SwingConstants.CENTER);
        needExperience.setHorizontalAlignment(SwingConstants.CENTER);
        currentExperience.setHorizontalAlignment(SwingConstants.CENTER);
        needMoney.setHorizontalAlignment(SwingConstants.CENTER);
        zhaohuanshou.setHorizontalAlignment(SwingConstants.LEFT);
        needQinmi.setHorizontalAlignment(SwingConstants.CENTER);
        currentQinmi.setHorizontalAlignment(SwingConstants.CENTER);

        // 组件设置字体颜色
        currentPoin.setForeground(Color.white);
        trainingProgress.setForeground(Color.white);
        needExperience.setForeground(Color.white);
        currentExperience.setForeground(Color.white);
        needMoney.setForeground(Color.white);
        zhaohuanshou.setForeground(Color.red);
        needQinmi.setForeground(Color.white);
        currentQinmi.setForeground(Color.white);

        // 组建设置字体
        currentPoin.setFont(UIUtils.TEXT_FONT1B);
        trainingProgress.setFont(UIUtils.TEXT_FONT1);
        needExperience.setFont(UIUtils.TEXT_FONT1);
        currentExperience.setFont(UIUtils.TEXT_FONT1);
        needMoney.setFont(UIUtils.TEXT_FONT1);
        zhaohuanshou.setFont(UIUtils.TEXT_HYK16);
        needQinmi.setFont(UIUtils.TEXT_FONT1);
        currentQinmi.setFont(UIUtils.TEXT_FONT1);

        // 组件透明化
        currentPoin.setOpaque(false);
        trainingProgress.setOpaque(false);
        needExperience.setOpaque(false);
        currentExperience.setOpaque(false);
        needMoney.setOpaque(false);
        exchangeBtn.setOpaque(false);
        promoteBtn.setOpaque(false);
        zhaohuanshou.setOpaque(false);
        needQinmi.setOpaque(false);
        currentQinmi.setOpaque(false);

        // 添加组件
        this.add(currentPoin);
        this.add(trainingProgress);
        this.add(needExperience);
        this.add(currentExperience);
        this.add(needMoney);
        this.add(zhaohuanshou);
        this.add(needQinmi);
		this.add(currentQinmi);
        this.add(exchangeBtn);
        this.add(promoteBtn);

    }

    /**
     *  面板获取数据 
     * @param
     * @param
     * @param
     * @param
     * @param
     * @param
     * @param
     */
    public void panelGetData(RoleSummoning pet) {
    	String lingxi = pet.getLingxi();
    	if (StringUtil.isNullOrEmpty(lingxi)) {
    		lingxi = "Lx=0&Lv=0&Point=0&Open=11001_0|11002_0|11003_0|11004_0|11005_0|11006_0|11007_0|11026_0|11045_0|11046_0";
    	}
    	String param[] = lingxi.split("&");
    	// 修炼等级
    	int xl = Integer.parseInt(param[1].split("=")[1]);
    	// 灵犀点数
    	int ds = Integer.parseInt(param[2].split("=")[1]);
    	
    	if (ds == 175) {
    		xl = 175;
    		this.getTrainingProgress().setFont(new Font("黑体",Font.PLAIN,14));
    		this.getTrainingProgress().setForeground(Color.RED);
    	}
    	
    	// 当前经验值
        this.getCurrentExperience().setText(pet.getExp().toString());
        // 当前修炼进度
        this.getTrainingProgress().setText(ds == 175 ? "登峰造极" :  (xl + "/" + (ds+1)));
        this.numExp = (int)(xl / (ds+1.0) * 166);
        // 当前灵犀点数
        this.getCurrentPoin().setText(ds + "");
        // 召唤兽名称
        this.getZhaohuanshou().setText(pet.getSummoningname());
        // 召唤兽亲密
        this.getCurrentQinmi().setText(pet.getFriendliness() + "");
        
    }

    private ImageIcon icon;
    private ImageIcon iconExp; //修炼进度
   

    @Override
    protected void paintComponent(Graphics g) {
        // TODO Auto-generated method stub
        super.paintComponent(g);
        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
        	if (icon == null) {
                icon = new ImageIcon("inkImg/old/background/S265.png");
            }
            g.drawImage(icon.getImage(), 0, 0, 401, 384, this);
            
            if (iconExp == null) {
                iconExp = new ImageIcon("inkImg/hongmu/soaringSkill/exp.png");
            }
            g.drawImage(iconExp.getImage(), 193, 71 ,numExp, 19, null);
            Util.drawMoney( g,
                    drawCenteredString(g, RoleData.getRoleData().getLoginResult().getGold().toString(), 170, 180,
                            UIUtils.TEXT_FONT1), 258);
        }else {
            if (icon == null) {
                icon = new ImageIcon("img/xy2uiimg/S265.png");
            }
            g.drawImage(icon.getImage(), 0, 0, 401, 384, this);

            if (iconExp == null) {
                iconExp = new ImageIcon("img/soaringSkill/exp.png");
            }
            g.drawImage(iconExp.getImage(), 193, 71 ,numExp, 19, null);
            Util.drawMoney( g,
                    drawCenteredString(g, RoleData.getRoleData().getLoginResult().getGold().toString(), 170, 180,
                            UIUtils.TEXT_FONT1), 258);
        }
    }

    /**
     * 居中算法
     * 
     * @param g
     *
     * @param text
     *
     * @param
     *
     */
    public int drawCenteredString(Graphics g, String text, int getX, int lonX, Font font) {
        // Get the FontMetrics
        FontMetrics metrics = g.getFontMetrics(font);
        // Determine the X coordinate for the text
        int x = lonX + (getX - metrics.stringWidth(text)) / 2;
        return x;

    }

    /** 当前天枢点 */
    public JLabel getCurrentPoin() {
        return currentPoin;
    }

    public void setCurrentPoin(JLabel currentPoin) {
        this.currentPoin = currentPoin;
    }

    public JLabel getTrainingProgress() {
        return trainingProgress;
    }

    public void setTrainingProgress(JLabel trainingProgress) {
        this.trainingProgress = trainingProgress;
    }

    public JLabel getNeedExperience() {
        return needExperience;
    }

    public void setNeedExperience(JLabel needExperience) {
        this.needExperience = needExperience;
    }

    public JLabel getCurrentExperience() {
        return currentExperience;
    }

    public void setCurrentExperience(JLabel currentExperience) {
        this.currentExperience = currentExperience;
    }

    public JLabel getNeedMoney() {
        return needMoney;
    }

    public void setNeedMoney(JLabel needMoney) {
        this.needMoney = needMoney;
    }

    public PetLxBtn getPromoteBtn() {
        return promoteBtn;
    }

    public void setPromoteBtn(PetLxBtn promoteBtn) {
        this.promoteBtn = promoteBtn;
    }

    public PetLxBtn getExchangeBtn() {
        return exchangeBtn;
    }

    public void setExchangeBtn(PetLxBtn exchangeBtn) {
        this.exchangeBtn = exchangeBtn;
    }

    public ImageIcon getIcon() {
        return icon;
    }

    public void setIcon(ImageIcon icon) {
        this.icon = icon;
    }

    public BigDecimal getNeedMoneyNum() {
        return needMoneyNum;
    }

    public void setNeedMoneyNum(BigDecimal needMoneyNum) {
        this.needMoneyNum = needMoneyNum;
    }

    public BigDecimal getNeedExperienceNum() {
        return needExperienceNum;
    }

    public void setNeedExperienceNum(BigDecimal needExperienceNum) {
        this.needExperienceNum = needExperienceNum;
    }

	public JLabel getZhaohuanshou() {
		return zhaohuanshou;
	}

	public void setZhaohuanshou(JLabel zhaohuanshou) {
		this.zhaohuanshou = zhaohuanshou;
	}

	public JLabel getNeedQinmi() {
		return needQinmi;
	}

	public void setNeedQinmi(JLabel needQinmi) {
		this.needQinmi = needQinmi;
	}

	public JLabel getCurrentQinmi() {
		return currentQinmi;
	}

	public void setCurrentQinmi(JLabel currentQinmi) {
		this.currentQinmi = currentQinmi;
	}

}
